﻿package mortal.game.view.loginNotice
{
    import com.gengine.utils.*;
    import com.mui.containers.*;
    import com.mui.containers.globalVariable.*;
    import com.mui.controls.*;
    import mortal.common.global.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.item.*;

    public class LoginNoticeItem extends GSprite
    {
        private var _noticeTxt:GTextFiled;
        private var _itemBox:GBox;
        private var _info:LoginNoticeInfo;

        public function LoginNoticeItem()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._noticeTxt = UIFactory.gTextField("", 0, 0, 650, 20, this, GlobalStyle.textFormatBai.setSize(13), true);
            this._itemBox = UIFactory.getUICompoment(GBox, 0, 0);
            this._itemBox.direction = GBoxDirection.HORIZONTAL;
            this._itemBox.horizontalGap = 2;
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._noticeTxt.dispose();
            this._noticeTxt = null;
            this._itemBox.dispose();
            this._itemBox = null;
            super.disposeImpl(param1);
            return;
        }// end function

        public function updateData(param1:LoginNoticeInfo) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            var _loc_4:ItemData = null;
            var _loc_5:BaseItem = null;
            this._info = param1;
            this._noticeTxt.htmlText = HTMLUtil.addColor(param1.notice, GlobalStyle.colorBai);
            if (this.type == 0)
            {
                this._noticeTxt.y = (37 - this._noticeTxt.textHeight) / 2;
            }
            else
            {
                this._noticeTxt.y = 0;
            }
            this._noticeTxt.y = (37 - this._noticeTxt.textHeight) / 2;
            if (param1.items.length > 0)
            {
                _loc_3 = param1.items.length;
                while (_loc_2 < _loc_3)
                {
                    
                    _loc_4 = param1.items[_loc_2];
                    _loc_5 = UIFactory.getUICompoment(BaseItem, 0, 0, this._itemBox);
                    _loc_5.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 2);
                    _loc_5.itemData = _loc_4;
                    _loc_2++;
                }
                this._itemBox.invalidate();
                if (!contains(this._itemBox))
                {
                    addChild(this._itemBox);
                }
                this._noticeTxt.y = (37 - this._noticeTxt.textHeight) / 2;
            }
            return;
        }// end function

        public function get type() : int
        {
            return this._info.type;
        }// end function

        public function updateBoxPos(param1:int) : void
        {
            if (this._itemBox && contains(this._itemBox))
            {
                this._itemBox.x = param1 + 10;
            }
            return;
        }// end function

        public function hasItemBox() : Boolean
        {
            return this._itemBox && this._itemBox.numChildren > 0;
        }// end function

        public function get textWidth() : int
        {
            return this._noticeTxt.textWidth;
        }// end function

        override public function get width() : Number
        {
            var _loc_1:* = this._noticeTxt.textWidth;
            if (this._itemBox && this._itemBox.numChildren > 0)
            {
                _loc_1 = _loc_1 + this._itemBox.numChildren * 37;
            }
            return _loc_1;
        }// end function

        override public function get height() : Number
        {
            if (this.type == 0 || this._itemBox && this._itemBox.numChildren > 0)
            {
                return 37;
            }
            return 20;
        }// end function

    }
}
